﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Runoi.StockQuantBrain.Entity
{
    /// <summary>
    /// 账户信息
    /// </summary>
    public class Account
    {
        /// <summary>
        /// 账户总余额
        /// </summary>
        public decimal Balance { get; set; }
        /// <summary>
        /// 可用资金
        /// </summary>
        public decimal AvailableFunds { get; set; }
        /// <summary>
        /// 冻结资金
        /// </summary>
        public decimal FrozenFunds { get; set; }

        /// <summary>
        /// 尝试扣除资金
        /// </summary>
        /// <param name="amount">扣除金额</param>
        /// <returns>扣除是否成功</returns>
        public bool TryWithdraw(decimal amount)
        {
            if (AvailableFunds >= amount) // 如果可用资金充足
            {
                AvailableFunds -= amount; // 减少可用资金
                FrozenFunds += amount;    // 增加冻结资金
                return true;
            }
            return false;
        }

        /// <summary>
        /// 存入资金
        /// </summary>
        /// <param name="amount">存入金额</param>
        public void Deposit(decimal amount)
        {
            Balance += amount;         // 增加账户总余额
            AvailableFunds += amount;  // 增加可用资金
        }
    }
}
